home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / DClap / DControl.cpp < prev    next >
Encoding:
Text File  |  1995-12-17  |  6.8 KB  |  306 lines  |  [TEXT/R*ch]

  1. // DControl.cp
  2. // d.g.gilbert
  3.  
  4.  
  5. #include "Dvibrant.h"
  6. #include "DControl.h"
  7. #include "DList.h"
  8. #include "DUtil.h"
  9.  
  10.  
  11.  
  12.  
  13. // class DControl  
  14.  
  15.  
  16.  
  17.  
  18. // class DCluster : DControl
  19.  
  20. extern "C" void groupActionProc(Nlm_GrouP    item)
  21. {
  22.     DCluster *obj= (DCluster*) Nlm_GetObject( (Nlm_GraphiC)item);
  23.     if (obj)  obj->IsMyViewAction(obj);
  24. }
  25.  
  26.  
  27. // fFont and SetFont are static
  28. Nlm_FonT DCluster::fFont = NULL;
  29.  
  30. void DCluster::SetFont( Nlm_FonT theFont)
  31. {
  32.     fFont= theFont;
  33. }
  34.  
  35.  
  36. DCluster::DCluster(long id, DView* itsSuperior, 
  37.     short width, short height, Boolean hidden, char* title) :
  38.     DControl( id, itsSuperior) 
  39.     if (hidden)
  40.         fGroup= Nlm_HiddenGroup( (Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, 
  41.             groupActionProc);
  42.     else
  43.         fGroup= Nlm_NormalGroup( (Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, title, 
  44.             fFont, groupActionProc);
  45.     this->SetNlmObject(fGroup);    
  46. }
  47.  
  48. DCluster::~DCluster()
  49. {
  50.  
  51. }
  52.  
  53.  
  54. //class DPrompt : public DControl
  55.  
  56. DPrompt::DPrompt(long id, DView* itsSuperior, char* title, short pixwidth, short pixheight, 
  57.     Nlm_FonT font, Justify just) :
  58.     DControl( id, itsSuperior) 
  59. {
  60.     fPrompt= Nlm_StaticPrompt((Nlm_WindoW)itsSuperior->GetNlmObject(), title, pixwidth, 
  61.                                 pixheight, font, just);  
  62.     this->SetNlmObject(fPrompt);    
  63. }
  64.  
  65.  
  66.  
  67.  
  68.     
  69.  
  70.  
  71.  
  72.  
  73. //class DPopupList : public DView
  74.     
  75. extern "C" void PopupListHandler(Nlm_PopuP p)
  76. {
  77.     DPopupList *obj= (DPopupList*) Nlm_GetObject((Nlm_GraphiC)p);
  78.     if (obj) obj->IsMyViewAction(obj);
  79. }
  80.  
  81. DPopupList::DPopupList(long id, DView* itsSuperior, Boolean macLike) :
  82.     DControl( id, itsSuperior) 
  83. {
  84.     fPopup= Nlm_PopupList((Nlm_GrouP)itsSuperior->GetNlmObject(), macLike, PopupListHandler);
  85.     this->SetNlmObject(fPopup);
  86.     //gViewCentral->RegisterView(id, fPopup, kMenu, this); << done by ::DView() 
  87.     //fItemList= new DList(NULL,DList::kOwnObjects + DList::kDeleteObjects);
  88.     fItemList= new DList(NULL);
  89. }
  90.  
  91.  
  92. DPopupList::~DPopupList()
  93. {
  94.     // dammit, DList( , kDeleteObjects) is NOT WORKING !! (not called obj destructors)
  95.     short i, n= fItemList->GetSize();
  96.     for (i=0; i<n; i++) {
  97.         DString* st= (DString*) fItemList->At(i);
  98.         delete st;
  99.         }
  100.     delete fItemList;
  101. }
  102.  
  103. #if FIX_THIS_LATER
  104. void  DPopupList::SetItemState(short item, Boolean enable) 
  105. {
  106.     DView* aview= (DView*)fPopupItemList->At(item);
  107.     if (aview) vobj= aview->fNlmObject;
  108.     if (enable) 
  109.         Nlm_EnableChoiceItem ( vobj, false, false);
  110.     else
  111.         Nlm_DisableChoiceItem ( vobj, false, false);
  112. }
  113. #endif
  114.  
  115. void  DPopupList::AddItem(char* title) 
  116. {
  117.     DString* s= new DString(title);
  118.     fItemList->InsertLast(s);
  119.     Nlm_PopupItem(fPopup, title);
  120. }
  121.  
  122. char* DPopupList::GetItemTitle( short item, char* title, ulong maxsize) 
  123.       if (item>0) {
  124.       DString* s= (DString*) fItemList->At(item-1);
  125.       if (s) {
  126.         char *cp= (char*) s->Get();
  127.         if (title==NULL) {
  128.           maxsize= StrLen(cp) + 1;
  129.           title= (char*) MemNew(maxsize);
  130.           }
  131.         StrNCpy(title, cp, maxsize);
  132.         }
  133.     }
  134.     return title;
  135. }
  136.  
  137. char* DPopupList::GetSelectedItem( short& item, char* name, ulong namesize) 
  138.     item= GetValue(); 
  139. #if 1
  140.     return this->GetItemTitle( item, name, namesize);
  141. #else
  142.   if (name && namesize) {
  143.       *name= 0;
  144.       if (item) {
  145.           DString* s= (DString*) fItemList->At(item-1);
  146.           StrNCpy(name, (char*)s->Get(), namesize);
  147.           }
  148.       }
  149. #endif
  150.   return name;
  151.     // this fails for MOTIF ... urgh
  152.     //return GetItemTitle(item, name, namesize); 
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. extern "C" void buttonActionProc(Nlm_ButtoN    item)
  161. {
  162.     DButton *obj= (DButton*) Nlm_GetObject( (Nlm_GraphiC)item);
  163.     if (obj)  obj->IsMyViewAction(obj);
  164. }
  165.  
  166. //class DButton : public DControl
  167.  
  168. DButton::DButton(long id, DView* itsSuperior, char* title):
  169.     DControl( id, itsSuperior) 
  170. {
  171.     fButton    = Nlm_PushButton( (Nlm_WindoW)itsSuperior->GetNlmObject(), title, buttonActionProc);
  172.     this->SetNlmObject(fButton);    
  173. }
  174.  
  175.  
  176. //class DDefaultButton : public DButton
  177.  
  178. DDefaultButton::DDefaultButton(long id, DView* itsSuperior, char* title):
  179.     DControl( id, itsSuperior) 
  180. {
  181.     fButton    = Nlm_DefaultButton((Nlm_WindoW)itsSuperior->GetNlmObject(), title, buttonActionProc);
  182.     this->SetNlmObject(fButton);    
  183. }
  184.  
  185.  
  186. //class DCheckBox : public DButton
  187.  
  188. DCheckBox::DCheckBox(long id, DView* itsSuperior, char* title):
  189.     DControl( id, itsSuperior) 
  190. {
  191.     fButton    = Nlm_CheckBox((Nlm_WindoW)itsSuperior->GetNlmObject(), title, buttonActionProc);
  192.     this->SetNlmObject(fButton);    
  193. }
  194.  
  195. //class DRadioButton : public DButton
  196.  
  197. DRadioButton::DRadioButton(long id, DView* itsSuperior, char* title):
  198.     DControl( id, itsSuperior) 
  199. {
  200.     fButton    = Nlm_RadioButton((Nlm_WindoW)itsSuperior->GetNlmObject(), title);
  201.     this->SetNlmObject(fButton);    
  202. }
  203.  
  204.  
  205.  
  206.  
  207.  
  208. //class DListBox : public DControl
  209.  
  210.  
  211. extern "C" void listboxActionProc(Nlm_LisT    item)
  212. {
  213.     DListBox *obj= (DListBox*) Nlm_GetObject( (Nlm_GraphiC)item);
  214.     if (obj)  obj->IsMyViewAction(obj);
  215. }
  216.  
  217. DListBox::DListBox(long id, DView* itsSuperior, 
  218.     short width, short height, Boolean multiselection):
  219.     DControl( id, itsSuperior) 
  220. {
  221.     if (multiselection)
  222.         fListBox= Nlm_MultiList((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, listboxActionProc);
  223.     else
  224.         fListBox= Nlm_SingleList((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, listboxActionProc);
  225.     this->SetNlmObject(fListBox);    
  226. }
  227.  
  228.  
  229.  
  230. //class DRepeatButton : public DControl
  231.  
  232. extern "C" void repeaterProc(Nlm_RepeaT item, Nlm_PoinT mouse)
  233. {
  234.     DRepeatButton *obj= (DRepeatButton*) Nlm_GetObject( (Nlm_GraphiC)item);
  235.     if (obj) obj->ClickAt(mouse);
  236. }
  237.  
  238. DRepeatButton::DRepeatButton(long id, DView* itsSuperior, char* title):
  239.     DControl( id, itsSuperior) 
  240. {
  241.     fRepeater= Nlm_RepeatButton((Nlm_WindoW)itsSuperior->GetNlmObject(), title, repeaterProc);
  242.     this->SetNlmObject(fRepeater);    
  243. }
  244.  
  245. void DRepeatButton::ClickAt( Nlm_PoinT mouse)
  246. {
  247.  
  248. }
  249.  
  250.  
  251.  
  252.  
  253. //class DScrollBar : public DControl
  254.  
  255. extern "C" void scrollbarProc(Nlm_BaR item, Nlm_GraphiC itsSlave, Nlm_Int2 newval, Nlm_Int2 oldval)
  256. {
  257.     DScrollBar *obj= (DScrollBar*) Nlm_GetObject( (Nlm_GraphiC)item);
  258.     DView *scrollee= (DView*) Nlm_GetObject( itsSlave);
  259.     // scrollee should == itsSuperior 
  260.     if (obj)  obj->Scroll(scrollee,newval,oldval);
  261. }
  262.  
  263. DScrollBar::DScrollBar(long id, DView* itsSuperior, short width, short height):
  264.     DControl( id, itsSuperior)
  265. {
  266.     fScrollbar=  Nlm_ScrollBar((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, scrollbarProc);
  267.     this->SetNlmObject(fScrollbar);    
  268. }
  269.  
  270. void DScrollBar::Scroll(DView* scrollee, short newval, short oldval)
  271. {
  272.     
  273. }
  274.  
  275.  
  276.  
  277.  
  278.  
  279. //class DSwitchBox : public DControl
  280.  
  281. extern "C" void switchProc(Nlm_SwitcH    item, short newval, short oldval)
  282. {
  283.     DSwitchBox *obj= (DSwitchBox*) Nlm_GetObject( (Nlm_GraphiC)item);
  284.     if (obj)  obj->Switch(newval, oldval);
  285. }
  286.  
  287. DSwitchBox::DSwitchBox(long id, DView* itsSuperior, Boolean displayTextOfValue, Boolean vertical):
  288.     DControl( id, itsSuperior)
  289. {
  290.     if (vertical)
  291.         fSwitch= Nlm_UpDownSwitch((Nlm_WindoW)itsSuperior->GetNlmObject(), displayTextOfValue, switchProc);
  292.     else
  293.         fSwitch= Nlm_LeftRightSwitch((Nlm_WindoW)itsSuperior->GetNlmObject(), displayTextOfValue, switchProc);
  294.     this->SetNlmObject(fSwitch);    
  295. }
  296.  
  297. void DSwitchBox::Switch(short newval, short oldval)
  298. {
  299.     
  300. }
  301.  
  302.  
  303.